import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.brandId)
        requiredFields.push(formatMessage({
            id: 'validator.message.brandId',
            defaultMessage: '品牌编号'
        }));
    if(!data || !data.code)
        requiredFields.push(formatMessage({
            id: 'validator.message.code',
            defaultMessage: '编号'
        }));
    if(!data || !data.name)
        requiredFields.push(formatMessage({
            id: 'validator.message.name',
            defaultMessage: '名称'
        }));
    if(!data || !data.region || data.region.length === 0)
        requiredFields.push(formatMessage({
            id: 'validator.message.are',
            defaultMessage: '国省市'
        }));
    if(!data || !data.address)
        requiredFields.push(formatMessage({
            id: 'validator.message.address',
            defaultMessage: '地址'
        }));
    if(!data || !data.contactNumber)
        requiredFields.push(formatMessage({
            id: 'validator.message.contactNumber',
            defaultMessage: '联系电话'
        }));
    if(!data || !data.fax)
        requiredFields.push(formatMessage({
            id: 'validator.message.fax',
            defaultMessage: '传真'
        }));
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.message.required',
            defaultMessage: '必填!'
        })}`);
        return false;
    }
    return true;
};

